from time import sleep

from selenium import  webdriver

driver = webdriver.Firefox()
#打开登录界面
driver.get('http://localhost/jxc/index.asp')
#完成登录
inputs=driver.find_elements_by_tag_name('input')
inputs[0].send_keys('admin')
inputs[1].send_keys('admin')
inputs[2].click()

#从当前框架切换到菜单框架中
driver.switch_to.frame('left')
#点击菜单，系统设置-计量单位管理
sysset_css = '.menuall > tbody:nth-child(1) > tr:nth-child(13) > td:nth-child(1)'
driver.find_element_by_css_selector(sysset_css).click()
danwei_css = '#g_6 > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(7) > td:nth-child(1)'
driver.find_element_by_css_selector(danwei_css).click()

#从当前菜单框架切换到右边框架中
driver.switch_to.default_content()
driver.switch_to.frame('right')
sleep(2)

#点击删除计量单位
cha_css = '.toptable > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(3) > input:nth-child(1)'
driver.find_element_by_css_selector(cha_css).click()
del_css = 'input.button:nth-child(2)'
driver.find_element_by_css_selector(del_css).click()
sleep(2)
driver.switch_to.alert.accept()
sleep(2)

#点击添加计量单位
add_css = 'input.button:nth-child(1)'
driver.find_element_by_css_selector(add_css).click()
sleep(2)
driver.find_element_by_name('danwei').send_keys('吨')
driver.find_element_by_name('submit').click()
sleep(2)
driver.switch_to.alert.accept()

#从右边框架切换到菜单框架
driver.switch_to.default_content()
driver.switch_to.frame('left')
sleep(2)

#点击菜单，系统设置-产品大类管理
sysset_css = '.menuall > tbody:nth-child(1) > tr:nth-child(13) > td:nth-child(1)'
driver.find_element_by_css_selector(sysset_css).click()
dalei_css = '#g_6 > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(5) > td:nth-child(1)'
driver.find_element_by_css_selector(dalei_css).click()

#从当前框架切换到菜单框架中
driver.switch_to.default_content()
driver.switch_to.frame('right')
sleep(2)

#点击添加大类
addd_css = 'input.button:nth-child(1)'
driver.find_element_by_css_selector(addd_css).click()
sleep(2)
driver.find_element_by_name('bigclass').send_keys('产品')
driver.find_element_by_name('submit').click()
sleep(2)
driver.switch_to.alert.accept()

#从当前框架切换到菜单框架中
driver.switch_to.default_content()
driver.switch_to.frame('left')
sleep(2)

#点击菜单，系统设置-产品大类管理
sysset_css = '.menuall > tbody:nth-child(1) > tr:nth-child(13) > td:nth-child(1)'
driver.find_element_by_css_selector(sysset_css).click()
dalei_css = '#g_6 > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(6) > td:nth-child(1)'
driver.find_element_by_css_selector(dalei_css).click()

#从当前框架切换到菜单框架中
driver.switch_to.default_content()
driver.switch_to.frame('right')
sleep(2)

#点击添加大类
addx_css = 'input.button:nth-child(1)'
driver.find_element_by_css_selector(addx_css).click()
sleep(2)
driver.find_element_by_name('smallclass').send_keys('产品')
driver.find_element_by_name('submit').click()
sleep(2)
driver.switch_to.alert.accept()

#退出系统
driver.switch_to.default_content()
driver.switch_to.frame('topFrame')
driver.find_element_by_link_text('安全退出').click()
driver.switch_to.alert.accept()
